<%--
  Created by IntelliJ IDEA.
  User: 金慧峰
  Date: 2023/11/21
  Time: 12:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>商品添加</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.js"></script>
</head>
<body>
    <table id="products">
        <tr>
            <th>欢迎您：</th>        <th id="name"></th>
        </tr>
        <tr>
            <td >
                <input type="button" value="添加多个商品" onclick="addProducts()">
            </td>
        </tr>
        <tr>
            <td>商品Id</td>
            <td>商品名称</td>
        </tr>

    </table>
    <script type="text/javascript">
        $(function () {
            let url = "${pageContext.request.contextPath}/getUser";
            $.get(url,function (data) {
                $("#name").text(data.username);
            });

        });
        function addProducts() {
            let url = "${pageContext.request.contextPath}/addProducts";
            $.get(url,function (data) {
                let str = "";
                for (let i = 0; i < data.length; i++) {
                    str += "<tr><td>"+data[i].id+"</td><td>"+data[i].name+"</td></tr>";
                }
                $("#products").append(str);
            });
        }
    </script>
</body>
</html>
